#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef __int128 ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=2147493647;

void mul(ll* a,ll* b,const int row,const int col)
{
	ll c[row][col];
    memset(c, 0, sizeof(c));
    for(int i=0; i<row; i++)
        for(int j=0; j<col; j++)
            for(int k=0; k<col; k++)
                c[i][j] = ((c[i][j] + a[i*col+k]*b[k*col+j]%mod))%mod;           
    memcpy(b,c,sizeof(c));
}

void qpow(ll* a,ll* b,int n,int row,int col)
{
	while(n)
	{
		if((n&1)==1)
		{
			mul(a,b,row,col);
		}
		n>>=1;
		mul(a,a,row,col);
	}
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,A,B;
		cin>>n>>A>>B;
		if(n==1)
		{
			cout<<A<<endl;
			continue;
		}
		if(n==2)
		{
			cout<<B<<endl;
			continue;
		}
		ll a[7][7]={0,1,0,0,0,0,0,
		             2,1,1,4,6,4,1,
					 0,0,1,4,6,4,1,
					 0,0,0,1,3,3,1,
					 0,0,0,0,1,2,1,
					 0,0,0,0,0,1,1,
					 0,0,0,0,0,0,1};
		ll b[7][7];
		memset(b,0,sizeof(b));
		b[0][0]=A;b[1][0]=B;
		int p=1;
		for(int i=6;i>=2;i--)
		{
			b[i][0]=p;
			p*=2;
		}
//				for(int i=0;i<=6;i++)
//		{
//			for(int j=0;j<=6;j++)
//			{
//				cout<<a[i][j]<<' ';
//			}
//			cout<<endl;
//		}
        ll* pa=&a[0][0];
		ll* pb=&b[0][0];
        qpow(pa,pb,n-2,7,7);
        cout<<(long long)b[1][0]<<endl;
	}

	return 0;
}

